package pl.grabar.clinic.core.domain.person;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

import pl.grabar.clinic.core.domain.enums.Gender;
import pl.grabar.clinic.core.domain.person.data.Address;
import pl.grabar.clinic.core.domain.person.data.PatientRecord;

/**
 * Klasa reprezentuje pacjenta
 * 
 * @author db
 * 
 */
@Entity
@Table(name = "PATIENT")
public class Patient implements Serializable {

	private static final long serialVersionUID = -9122887049341883462L;

	@Id
	@GeneratedValue
	@JsonIgnore
	private long id;

	@Column(name = "FIRST_NAME", nullable = false)
	private String firstName;
	
	@Column(name = "SECOND_NAME")
	private String secondName;

	@Column(name = "LAST_NAME", nullable = false)
	private String lastName;

	@JsonIgnore
	@OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
	@JoinColumn(name = "PATIENT_RECORD_ID")
	private PatientRecord patientRecord;

	@OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "ADDRESS_ID")
	@JsonIgnore
	private Address address;

	@Column
	private String pesel;

	@Enumerated(EnumType.STRING)
	private Gender gender;

	@Column(name = "DATE_OF_BIRTH")
	private Date dateOfBirth;

	@Column
	private int age;
	
	@Column(name="PHONE_NUMBER")
	private String phoneNumber;

	public Patient() {
		dateOfBirth = new Date();
	}

	@JsonIgnore
	public String getFullName(){
		return this.firstName + " " + this.lastName;
	}
	/* AKCESORY */

	public PatientRecord getPatientRecord() {
		return patientRecord;
	}

	public void setPatientRecord(PatientRecord patientRecord) {
		this.patientRecord = patientRecord;
	}

	public String getPesel() {
		return pesel;
	}

	public void setPesel(String pesel) {
		this.pesel = pesel;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}

}
